package logic

import (
	"api/model/mysql"
	"context"
	"goods_srv/goods"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *goods.AddRequest) (*goods.AddResponse, error) {
	// todo: add your logic here and delete this line

	m := mysql.Goods{
		GoodsImg:    in.GoodsImg,
		GoodsName:   in.GoodsName,
		GoodsNum:    int(in.GoodsNum),
		GoodsPrice:  float64(in.GoodsPrice),
		GoodsStatus: 1,
	}
	mysql.DB.Create(&m)

	return &goods.AddResponse{
		Id: int64(m.ID),
	}, nil
}
